#import "GKCover.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheyprofessionalincidentally.h"
#import "dfhgwhruebvhrheygarbageequator.h"
#import "dfhgwhruebvhrheymisunderstandvacant.h"
#import "dfhgwhruebvhrheydiscardreveal.h"
#import "dfhgwhruebvhrheypeapasture.h"
#import "dfhgwhruebvhrheylaserbeforehandViewController.h"
#import "dfhgwhruebvhrheybeforehandversionViewController.h"
@interface dfhgwhruebvhrheylaserbeforehandViewController ()
@property (nonatomic, assign) BOOL isExpand;
@property (nonatomic, strong) dispatch_group_t group;
@property (nonatomic, strong) dhgfywegwygeydwprevalentconnection *maxCoupon;
@property (nonatomic, strong) NSMutableArray<dhgfywegwygeydwprevalentconnection *> *couponList;
@end
@implementation dfhgwhruebvhrheylaserbeforehandViewController {
    UIView *bgView;
    UIView *topView;
    UILabel *amountLabel;
    UILabel *topTipsLabel;
    UIView *line;
    dfhgwhruebvhrheydiscardreveal *dateView;
    dfhgwhruebvhrheydiscardreveal *principalView;
    dfhgwhruebvhrheydiscardreveal *interestView;
    dfhgwhruebvhrheydiscardreveal *overdueDaysView;
    dfhgwhruebvhrheydiscardreveal *overdueFeesView;
    dfhgwhruebvhrheydiscardreveal *repaidAmountView;
    dfhgwhruebvhrheydiscardreveal *couponView;
    UIButton *paymentBtn;
    UIView *installmentView;
    UIButton *fullPaymentBtn;
    UILabel *installmentTips;
    UIView *secondInstallmentView;
    UILabel *secondInstallmentLabel;
    UIImageView *secondInstallmentIcon;
    UIView *secondInstallmentLine;
    dfhgwhruebvhrheydiscardreveal *secondDateView;
    dfhgwhruebvhrheydiscardreveal *secondAmountView;
    UIView *secondInstallmentInfoView;
    dfhgwhruebvhrheydiscardreveal *secondPrincipalView;
    dfhgwhruebvhrheydiscardreveal *secondInterestView;
    UIButton *secondFullPaymentBtn;
    UILabel *tipsLabel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadUI];
    [self loadData];
}
- (void)loadUI {
    [self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
    [self configRightIcon:@"navigation_right"];
    self.navigationItem.title = @"Bill Details";
    self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
    bgView = [[UIView alloc] init];
    bgView.layer.cornerRadius = 20;
    bgView.layer.masksToBounds = YES;
    bgView.backgroundColor = [UIColor whiteColor];
    [self.containerView addSubview:bgView];
    topView = [[UIView alloc] init];
    topView.backgroundColor = second_color.dhgfywegwygeydwlearneddesignate;
    [bgView addSubview:topView];
    amountLabel = [[UILabel alloc] init];
    amountLabel.font = [UIFont bold:28];
    amountLabel.textColor = primary_color.dhgfywegwygeydwlearneddesignate;
    [topView addSubview:amountLabel];
    topTipsLabel = [[UILabel alloc] init];
    topTipsLabel.font = [UIFont regular:15];
    topTipsLabel.textColor = primary_color.dhgfywegwygeydwlearneddesignate;
    [topView addSubview:topTipsLabel];
    line = [[UIView alloc] init];
    [topView addSubview:line];
    dateView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    dateView.backgroundColor = second_color.dhgfywegwygeydwlearneddesignate;
    [dateView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [topView addSubview:dateView];
    principalView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    [principalView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [bgView addSubview:principalView];
    interestView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    [interestView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [bgView addSubview:interestView];
    overdueDaysView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    [overdueDaysView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [bgView addSubview:overdueDaysView];
    overdueFeesView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    [overdueFeesView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [bgView addSubview:overdueFeesView];
    repaidAmountView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    [repaidAmountView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [bgView addSubview:repaidAmountView];
    couponView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    couponView.tag = 100;
    [couponView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [bgView addSubview:couponView];
    UITapGestureRecognizer *couponViewTap = [[UITapGestureRecognizer alloc] init];
    [couponViewTap addTarget:self action:@selector(repayViewTapAction:)];
    [couponView addGestureRecognizer:couponViewTap];
    paymentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    paymentBtn.tag = 100;
    paymentBtn.layer.cornerRadius = 10;
    paymentBtn.backgroundColor = second_color.dhgfywegwygeydwlearneddesignate;
    [paymentBtn setTitle:@"Repay" forState:UIControlStateNormal];
    [paymentBtn setTitleColor:primary_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
    [self.containerView addSubview:paymentBtn];
    [paymentBtn addTarget:self action:@selector(replymentViewBtnsAction:) forControlEvents:UIControlEventTouchUpInside];
    installmentView = [[UIView alloc] init];
    [self.containerView addSubview:installmentView];
    fullPaymentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fullPaymentBtn.tag = 101;
    fullPaymentBtn.layer.cornerRadius = 10;
    fullPaymentBtn.titleLabel.font = [UIFont semiBold:18];
    fullPaymentBtn.backgroundColor = [UIColor whiteColor];
    [fullPaymentBtn setTitle:@"Full Payment" forState:UIControlStateNormal];
    [fullPaymentBtn setTitleColor:primary_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
    [installmentView addSubview:fullPaymentBtn];
    [fullPaymentBtn addTarget:self action:@selector(replymentViewBtnsAction:) forControlEvents:UIControlEventTouchUpInside];
    installmentTips = [[UILabel alloc] init];
    installmentTips.font = [UIFont regular:13];
    installmentTips.numberOfLines = 0;
    installmentTips.textColor = [UIColor whiteColor];
    installmentTips.text = @"After the second installment expires, only the full repayment option is available";
    [installmentView addSubview:installmentTips];
    secondInstallmentView = [[UIView alloc] init];
    secondInstallmentView.tag = 200;
    secondInstallmentView.layer.cornerRadius = 10;
    secondInstallmentView.backgroundColor = [UIColor whiteColor];
    [installmentView addSubview:secondInstallmentView];
    UITapGestureRecognizer *installmentViewTap = [[UITapGestureRecognizer alloc] init];
    [installmentViewTap addTarget:self action:@selector(repayViewTapAction:)];
    [secondInstallmentView addGestureRecognizer:installmentViewTap];
    secondInstallmentLabel = [[UILabel alloc] init];
    secondInstallmentLabel.text = @"Second installment";
    secondInstallmentLabel.font = [UIFont regular:15];
    secondInstallmentLabel.textColor = @"#3B414B".dhgfywegwygeydwlearneddesignate;
    [secondInstallmentView addSubview:secondInstallmentLabel];
    secondInstallmentIcon = [[UIImageView alloc] init];
    secondInstallmentIcon.image = [UIImage imageNamed:@"more"];
    [secondInstallmentView addSubview:secondInstallmentIcon];
    secondInstallmentLine = [[UIView alloc] init];
    secondInstallmentLine.hidden = YES;
    secondInstallmentLine.backgroundColor = @"#E6E6E6".dhgfywegwygeydwlearneddesignate;
    [secondInstallmentView addSubview:secondInstallmentLine];
    secondDateView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    secondDateView.hidden = YES;
    [secondDateView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [secondInstallmentView addSubview:secondDateView];
    secondAmountView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    secondAmountView.hidden = YES;
    [secondAmountView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [secondAmountView updateTopConstraints:0];
    [secondInstallmentView addSubview:secondAmountView];
    secondInstallmentInfoView = [[UIView alloc] init];
    secondInstallmentInfoView.hidden = YES;
    secondInstallmentInfoView.layer.cornerRadius = 10;
    secondInstallmentInfoView.layer.masksToBounds = YES;
    secondInstallmentInfoView.backgroundColor = @"#F6F6F6".dhgfywegwygeydwlearneddesignate;
    [secondInstallmentView addSubview:secondInstallmentInfoView];
    secondPrincipalView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    secondPrincipalView.hidden = YES;
    secondPrincipalView.backgroundColor = @"#FAFAFA".dhgfywegwygeydwlearneddesignate;
    [secondPrincipalView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [secondInstallmentInfoView addSubview:secondPrincipalView];
    secondInterestView = [[dfhgwhruebvhrheydiscardreveal alloc] init];
    secondInterestView.hidden = YES;
    secondInterestView.backgroundColor = @"#FAFAFA".dhgfywegwygeydwlearneddesignate;
    [secondInterestView updateTitle:@"" andValue:@"" isHiddenLine:YES];
    [secondInterestView updateTopConstraints:0];
    [secondInstallmentInfoView addSubview:secondInterestView];
    secondFullPaymentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    secondFullPaymentBtn.tag = 102;
    secondFullPaymentBtn.hidden = YES;
    secondFullPaymentBtn.layer.cornerRadius = 22.5;
    secondFullPaymentBtn.titleLabel.font = [UIFont bold:18];
    secondFullPaymentBtn.backgroundColor = second_color.dhgfywegwygeydwlearneddesignate;
    [secondFullPaymentBtn setTitle:@"Full Payment" forState:UIControlStateNormal];
    [secondFullPaymentBtn setTitleColor:primary_color.dhgfywegwygeydwlearneddesignate forState:UIControlStateNormal];
    [secondFullPaymentBtn addTarget:self action:@selector(replymentViewBtnsAction:) forControlEvents:UIControlEventTouchUpInside];
    [secondInstallmentView addSubview:secondFullPaymentBtn];
    tipsLabel = [[UILabel alloc] init];
    tipsLabel.font = [UIFont regular:14];
    tipsLabel.numberOfLines = 0;
    tipsLabel.textColor = [UIColor whiteColor];
    tipsLabel.text = @"Warming Tips:\nRepay on time, you can get a higher loan amount and a longer loan term next time.";
    [self.containerView addSubview:tipsLabel];
}
- (void)setCoupon:(dhgfywegwygeydwprevalentconnection *)coupon {
    _coupon = coupon;
    self.maxCoupon = coupon;
}
- (void)loadData {
    if (self.group == nil) {
        self.group = dispatch_group_create();
    }
    if (self.repayment == nil) {
        dispatch_group_enter(self.group);
        [self getRepaymentData];
    }
    dispatch_group_enter(self.group);
    [self getUserCouponList];
    [dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
    __weak typeof(self) weakSelf = self;
    dispatch_group_notify(self.group, dispatch_get_main_queue(), ^{
        __strong typeof(weakSelf) strongSelf = weakSelf;
        [dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
        [strongSelf bindData];
    });
}
- (void)getRepaymentData {
    if (![dfhgwhruebvhrheyoptionsaving isLogin]) {
        return;
    }
    __weak typeof(self) weakSelf = self;
    [[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:repaymentDataApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        dfhgwhruebvhrheygarbageequator *repayment = [dfhgwhruebvhrheygarbageequator yy_modelWithJSON:json];
        if (repayment.code == 200) {
            strongSelf.repayment = repayment;
        }else {
            [dfhgwhruebvhrheyoptionsaving.keyWindow show:repayment.error];
        }
        dispatch_group_leave(strongSelf.group);
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        dispatch_group_leave(strongSelf.group);
    }];
}
- (void)getUserCouponList {
    __weak typeof(self) weakSelf = self;
    self.couponList = [@[] mutableCopy];
    [[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:userCouponListApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        dfhgwhruebvhrheyprofessionalincidentally *couponModel = [dfhgwhruebvhrheyprofessionalincidentally yy_modelWithJSON:json];
        if (couponModel.code == 200) {
            for (dhgfywegwygeydwprevalentconnection *item in couponModel.data) {
                if (strongSelf.coupon) {
                    strongSelf.maxCoupon = strongSelf.coupon;
                }else {
                    if (item.arch_money > strongSelf.maxCoupon.arch_money) {
                        strongSelf.maxCoupon = item;
                    }
                }
                item.type = 2;
                [strongSelf.couponList addObject:item];
            }
            strongSelf.maxCoupon.selected = YES;
        }else {
            [dfhgwhruebvhrheyoptionsaving.keyWindow show:couponModel.error];
        }
        dispatch_group_leave(strongSelf.group);
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        dispatch_group_leave(strongSelf.group);
    }];
}
- (void)bindData {
    if(self.repayment) {
        topTipsLabel.text = @"Total first installment repayment";
        if(self.repayment.is_ins_repay == 0) {
            installmentView.hidden = YES;
            [installmentView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(0);
            }];
            if(self.maxCoupon) {
                int couponAmount = self.maxCoupon.selected ? self.maxCoupon.arch_money : 0;
                [couponView updateTitle:@"Coupon" andValue:[NSString stringWithFormat:@"-PHP %d", couponAmount] isHiddenLine:YES];
            }else {
                couponView.hidden = YES;
                [couponView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.height.mas_equalTo(0);
                }];
            }
            if(self.repayment.is_instalment == 1) {
                if(self.repayment.is_normal_instalment == 1) {
                    topTipsLabel.text = @"Total second installment repayment";
                }else {
                    topTipsLabel.text = @"Full Repayment";
                    [paymentBtn setTitle:@"Full Repayment" forState:UIControlStateNormal];
                    tipsLabel.text = @"Warming Tips:\n1. Repay on time, you can get a higher loanamount and a longer loan term next time.\n2. The first installment has not been repaid, andthe second installment needs to be repaid in full";
                    [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.height.mas_equalTo(100);
                    }];
                }
            }else {
                topTipsLabel.text = @"Total Repayment";
            }
        }else {
            [paymentBtn setTitle:@"Installment" forState:UIControlStateNormal];
            couponView.hidden = YES;
            [couponView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(0);
            }];
            [secondDateView updateTitle:@"Repayment Date" andValue:[dfhgwhruebvhrheyoptionsaving formatTime:[self.repayment.pay_data.back_time intValue] WithDateFormat:@"MM/dd/yyyy"] isHiddenLine:YES];
            NSString *secondAmountString = [NSString stringWithFormat:@"%d",self.repayment.pay_data.money].dhgfywegwygeydwlocalitylearned;
            [secondAmountView updateTitle:@"Total Repayment Amount" andValue:[NSString stringWithFormat:@"PHP %@",secondAmountString] isHiddenLine:YES];
            NSString *secondPrincipalString = self.repayment.pay_data.principal.dhgfywegwygeydwlocalitylearned;
            [secondPrincipalView updateTitle:@"Principal" andValue:[NSString stringWithFormat:@"PHP %@",secondPrincipalString] isHiddenLine:YES];
            NSString *secondInterestString = [NSString stringWithFormat:@"%d",self.repayment.pay_data.interest].dhgfywegwygeydwlocalitylearned;
            [secondInterestView updateTitle:@"Interest" andValue:[NSString stringWithFormat:@"PHP %@",secondInterestString] isHiddenLine:YES];
        }
        CGFloat top = installmentView.isHidden ? 30 : 40;
        [paymentBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bgView.mas_bottom).offset(top);
        }];
        NSString *amountString;
        int amount = self.repayment.is_ins_repay == 1 ? self.repayment.current_amount : self.repayment.final_amount;
        if(self.repayment.is_ins_repay == 0) {
            int couponAmount = self.maxCoupon.selected ? self.maxCoupon.arch_money : 0;
            amountString = [NSString stringWithFormat:@"%d",amount - couponAmount].dhgfywegwygeydwlocalitylearned;
        }else {
            amountString = [NSString stringWithFormat:@"%d",amount].dhgfywegwygeydwlocalitylearned;
        }
        amountLabel.text = [NSString stringWithFormat:@"PHP %@",amountString];
        NSString *principalString = self.repayment.is_ins_repay == 0 ? self.repayment.money.dhgfywegwygeydwlocalitylearned : self.repayment.ins_amount.dhgfywegwygeydwlocalitylearned;
        [principalView updateTitle:@"Principal" andValue:[NSString stringWithFormat:@"PHP %@",principalString] isHiddenLine:NO];
        [dateView updateTitle:@"Repayment Date" andValue:[dfhgwhruebvhrheyoptionsaving formatTime:self.repayment.repay_time WithDateFormat:@"MM/dd/yyyy"] isHiddenLine:YES];
        NSString *interestString = self.repayment.is_ins_repay == 0 ? [NSString stringWithFormat:@"%d",self.repayment.all_interest].dhgfywegwygeydwlocalitylearned : [NSString stringWithFormat:@"%d",self.repayment.interest].dhgfywegwygeydwlocalitylearned;
        [interestView updateTitle:@"Interest" andValue:[NSString stringWithFormat:@"PHP %@",interestString] isHiddenLine:NO];
        if(self.repayment.overtime_day == 0) {
            overdueDaysView.hidden = YES;
            [overdueDaysView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(0);
            }];
        }else {
            [overdueDaysView updateTitle:@"Overdue Days" andValue:[NSString stringWithFormat:@"%d days", self.repayment.overtime_day] isHiddenLine:NO];
        }
        if(self.repayment.overtime_price == 0) {
            overdueFeesView.hidden = YES;
            [overdueFeesView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(0);
            }];
        }else {
            NSString *overtime_priceString = [NSString stringWithFormat:@"%d",self.repayment.overtime_price].dhgfywegwygeydwlocalitylearned;
            [overdueFeesView updateTitle:@"Overdue Fees" andValue:[NSString stringWithFormat:@"PHP %@",overtime_priceString] isHiddenLine:NO];
        }
        if([self.repayment.repaid_amount intValue] == 0) {
            repaidAmountView.hidden = YES;
            [repaidAmountView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(0);
            }];
        }else {
            NSString *repaidString = [NSString stringWithFormat:@"%@",self.repayment.repaid_amount].dhgfywegwygeydwlocalitylearned;
            [repaidAmountView updateTitle:@"Repaid Amount" andValue:[NSString stringWithFormat:@"PHP %@",repaidString] isHiddenLine:NO];
        }
    }
}
- (void)showCouponListView {
    __weak typeof(self) weakSelf = self;
    dfhgwhruebvhrheymisunderstandvacant *popView = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheymisunderstandvacant" owner:nil options:nil].firstObject;
    popView.frame = CGRectMake(0, 0, dhgfywegwygeydwdispositionvisualize, 362);
    [GKCover coverFrom:dfhgwhruebvhrheyoptionsaving.keyWindow contentView:popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleBottom showAnimStyle:GKCoverShowAnimStyleBottom hideAnimStyle:GKCoverHideAnimStyleBottom notClick:YES];
    [popView bindCouponList:self.couponList andCallBack:^(UIButton * _Nonnull sender, dhgfywegwygeydwprevalentconnection * _Nonnull select) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        if (sender.tag == 200) {
            strongSelf.maxCoupon = select;
            [strongSelf bindData];
        }
        [GKCover hideCover];
    }];
}
- (void)backAction {
    if (self.fromCouponList) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)repayViewTapAction:(UITapGestureRecognizer *)ges {
    switch (ges.view.tag) {
        case 100:{
            [self showCouponListView];
        }
            break;
        case 200: {
            self.isExpand = !self.isExpand;
            CGFloat height = self.isExpand ? 303 : 50;
            secondInstallmentLine.hidden = secondDateView.hidden = secondAmountView.hidden = secondInstallmentInfoView.hidden = secondPrincipalView.hidden = secondInterestView.hidden = secondFullPaymentBtn.hidden = !self.isExpand;
            NSString *icon = self.isExpand ? @"up" : @"more";
            secondInstallmentIcon.image = [UIImage imageNamed:icon];
            [secondInstallmentView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(height);
            }];
        }
            break;
        default:
            break;
    }
}
- (void)popFullRepayView {
    dfhgwhruebvhrheypeapasture *popView = [[dfhgwhruebvhrheypeapasture alloc] init];
    [GKCover coverFrom:dfhgwhruebvhrheyoptionsaving.keyWindow contentView:popView style:GKCoverStyleTranslucent showStyle:GKCoverShowStyleCenter showAnimStyle:GKCoverShowAnimStyleCenter hideAnimStyle:GKCoverHideAnimStyleCenter notClick:NO];
    [popView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(dfhgwhruebvhrheyoptionsaving.keyWindow);
        make.left.equalTo(dfhgwhruebvhrheyoptionsaving.keyWindow).offset(13);
    }];
    popView.coupon = self.maxCoupon;
    popView.existCouopon = self.couponList.count;
    [popView bindData:self.repayment andCallBack:^(int type) {
        [GKCover hideCover];
        if(type == 1) {
            [self showCouponListView];
        }else {
            [self go2Repayment:1];
        }
    }];
}
- (void)go2Repayment:(int)type {
    dfhgwhruebvhrheybeforehandversionViewController *resultVC = (dfhgwhruebvhrheybeforehandversionViewController *)[UIStoryboard storyboard:@"Home" withidentifier:@"repayment"];
    if(type == 3) {
        resultVC.amountString = amountLabel.text;
    }else {
        resultVC.coupon_id = self.maxCoupon.coupon_id;
        resultVC.amountString = [NSString stringWithFormat:@"%d",self.repayment.final_amount - (self.maxCoupon.selected ? self.maxCoupon.arch_money : 0)].dhgfywegwygeydwlocalitylearned;
    }
    resultVC.type = type;
    resultVC.repayment = self.repayment;
    [self.navigationController pushViewController:resultVC animated:YES];
}
- (void)replymentViewBtnsAction:(UIButton *)sender {
    if(self.repayment == nil) {
        [self loadData];
    }else {
        switch (sender.tag) {
            case 100: {
                if(self.repayment.is_ins_repay == 1) {
                    [self go2Repayment:3];
                }else {
                    [self go2Repayment:1];
                }
            }
                break;
            case 101:
            case 102:{
                [self popFullRepayView];
            }
                break;
            default:
                break;
        }
    }
}
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.containerView).offset(13);
        make.top.equalTo(self.containerView).offset(15);
        make.centerX.equalTo(self.containerView);
    }];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(bgView);
        make.height.mas_equalTo(145);
    }];
    [amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView).offset(15);
        make.centerX.equalTo(topView);
        make.height.mas_equalTo(40);
    }];
    [topTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(amountLabel.mas_bottom).offset(5);
        make.centerX.equalTo(amountLabel);
        make.height.mas_equalTo(21);
    }];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topTipsLabel.mas_bottom).offset(15);
        make.left.right.equalTo(topView);
        make.height.mas_equalTo(1);
    }];
    [self.view layoutIfNeeded];
    [line drawDashLine:primary_color.dhgfywegwygeydwlearneddesignate];
    [dateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerX.equalTo(topView);
        make.top.equalTo(line.mas_bottom);
    }];
    [principalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom);
        make.left.centerX.equalTo(topView);
    }];
    [interestView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(principalView.mas_bottom);
        make.left.centerX.equalTo(topView);
    }];
    [overdueDaysView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(interestView.mas_bottom);
        make.left.centerX.equalTo(topView);
    }];
    [overdueFeesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(overdueDaysView.mas_bottom);
        make.left.centerX.equalTo(topView);
    }];
    [repaidAmountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(overdueFeesView.mas_bottom);
        make.left.centerX.equalTo(topView);
    }];
    [couponView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(repaidAmountView.mas_bottom);
        make.left.centerX.equalTo(topView);
        make.bottom.equalTo(bgView);
    }];
    [paymentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom).offset(40).priorityHigh();
        make.left.centerX.equalTo(bgView);
        make.height.mas_equalTo(45);
    }];
    [installmentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(paymentBtn.mas_bottom);
        make.left.centerX.equalTo(self.containerView);
    }];
    [fullPaymentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(installmentView).offset(13);
        make.top.equalTo(installmentView).offset(20);
        make.centerX.equalTo(installmentView);
        make.height.mas_equalTo(45);
    }];
    [installmentTips mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(fullPaymentBtn.mas_bottom).offset(15);
        make.left.equalTo(fullPaymentBtn).offset(15);
        make.centerX.equalTo(installmentView);
        make.height.mas_equalTo(38);
    }];
    [secondInstallmentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(installmentTips.mas_bottom).offset(30);
        make.height.mas_equalTo(50).priorityHigh();
        make.left.centerX.equalTo(fullPaymentBtn);
        make.bottom.equalTo(installmentView).priorityHigh();
    }];
    [secondInstallmentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondInstallmentView).offset(16);
        make.left.equalTo(secondInstallmentView).offset(15);
        make.height.mas_equalTo(21);
    }];
    [secondInstallmentIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(secondInstallmentLabel);
        make.size.mas_equalTo(CGSizeMake(13, 13));
        make.right.equalTo(secondInstallmentView).offset(-15);
    }];
    [secondInstallmentLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondInstallmentView).offset(50);
        make.left.right.equalTo(secondInstallmentView);
        make.height.mas_equalTo(0.5);
    }];
    [secondDateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondInstallmentLine.mas_bottom);
        make.left.centerX.equalTo(secondInstallmentView);
        make.height.mas_equalTo(41);
    }];
    [secondAmountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(secondDateView);
        make.top.equalTo(secondDateView.mas_bottom);
        make.left.centerX.equalTo(secondInstallmentView);
    }];
    [secondInstallmentInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(secondInstallmentView).offset(15);
        make.top.equalTo(secondAmountView.mas_bottom);
        make.centerX.equalTo(secondInstallmentView);
        make.height.mas_equalTo(85);
    }];
    [secondPrincipalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.centerX.equalTo(secondInstallmentInfoView);
        make.height.equalTo(secondInterestView);
    }];
    [secondInterestView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondPrincipalView.mas_bottom);
        make.left.centerX.bottom.equalTo(secondInstallmentInfoView);
    }];
    [secondFullPaymentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(secondInstallmentInfoView.mas_bottom).offset(20);
        make.left.equalTo(secondInstallmentView).offset(15);
        make.centerX.equalTo(secondInstallmentView);
        make.height.mas_equalTo(45);
    }];
    [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(installmentView.mas_bottom).offset(30);
        make.left.centerX.equalTo(secondInstallmentView);
        make.height.mas_equalTo(60).priorityHigh();
        make.bottom.equalTo(self.containerView).offset(-15);
    }];
}
@end
